﻿//==================================================================
// Copyright (C) 2011 深圳市中旭企业管理股份有限公司
// 文件名: V_bpm_OpenClassBudgetMaster.cs
// 作 者：代码自动生成
// 日 期：2013-3-11 16:02:45
// 描 述：
// 版 本：1.00
// 修改历史纪录
// 版 本  修改时间      修改人            修改内容
// 1.00             
//==================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using System.Text;
using Csla;
using lite;
using Csla.Validation;
using Csla.Data;
using System.Data.SqlClient;
using ZX.DAL;
using OpenExpressApp.ORM;

namespace ZX.CRM.Library
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    [Table(Name = "V_bpm_OpenClassBudgetMaster")]
    [ZX.DBModule.Table("V_bpm_OpenClassBudgetMaster", "OcbdID")]
    public class V_bpm_OpenClassBudgetMaster : ZX.DBModule.BaseEntity
    {
        #region Business Methods 业务方法
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<Guid> OcbdIDProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<Guid>("OcbdID"));
        [DataObjectField(true, true)]
        [Column, PK]
        public Guid OcbdID
        {
            get { return GetProperty(OcbdIDProperty); }
            set { SetProperty(OcbdIDProperty, value); }
        }

        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<Guid> IDProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<Guid>("ID"));
        [Column]
        public Guid ID
        {
            get { return GetProperty(IDProperty); }
            set { SetProperty(IDProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<DateTime> BeginDateProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<DateTime>("BeginDate"));
        [Column]
        public DateTime BeginDate
        {
            get { return GetProperty(BeginDateProperty); }
            set { SetProperty(BeginDateProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<string> txtProductLayoutIDProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<string>("txtProductLayoutID"));
        [Column]
        public string txtProductLayoutID
        {
            get { return GetProperty(txtProductLayoutIDProperty); }
            set { SetProperty(txtProductLayoutIDProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<string> ProductLayoutIDProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<string>("ProductLayoutID"));
        [Column]
        public string ProductLayoutID
        {
            get { return GetProperty(ProductLayoutIDProperty); }
            set { SetProperty(ProductLayoutIDProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<int> RecIDProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<int>("RecID"));
        [Column]
        public int RecID
        {
            get { return GetProperty(RecIDProperty); }
            set { SetProperty(RecIDProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<string> ContactProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<string>("Contact"));
        [Column]
        public string Contact
        {
            get { return GetProperty(ContactProperty); }
            set { SetProperty(ContactProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<string> SubjectProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<string>("Subject"));
        [Column]
        public string Subject
        {
            get { return GetProperty(SubjectProperty); }
            set { SetProperty(SubjectProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<string> ProjectProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<string>("Project"));
        [Column]
        public string Project
        {
            get { return GetProperty(ProjectProperty); }
            set { SetProperty(ProjectProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<string> DetailsProjectProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<string>("DetailsProject"));
        [Column]
        public string DetailsProject
        {
            get { return GetProperty(DetailsProjectProperty); }
            set { SetProperty(DetailsProjectProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<decimal> BudgetAmountProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<decimal>("BudgetAmount"));
        [Column]
        public decimal BudgetAmount
        {
            get { return GetProperty(BudgetAmountProperty); }
            set { SetProperty(BudgetAmountProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<decimal> ActualAmountProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<decimal>("ActualAmount"));
        [Column]
        public decimal ActualAmount
        {
            get { return GetProperty(ActualAmountProperty); }
            set { SetProperty(ActualAmountProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<string> RemarkProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<string>("Remark"));
        [Column]
        public string Remark
        {
            get { return GetProperty(RemarkProperty); }
            set { SetProperty(RemarkProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<string> DetailsExpensesProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<string>("DetailsExpenses"));
        [Column]
        public string DetailsExpenses
        {
            get { return GetProperty(DetailsExpensesProperty); }
            set { SetProperty(DetailsExpensesProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<string> PrecautionsProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<string>("Precautions"));
        [Column]
        public string Precautions
        {
            get { return GetProperty(PrecautionsProperty); }
            set { SetProperty(PrecautionsProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<string> bpmTitleProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<string>("bpmTitle"));
        [Column]
        public string bpmTitle
        {
            get { return GetProperty(bpmTitleProperty); }
            set { SetProperty(bpmTitleProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<decimal> TotalAmountProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<decimal>("TotalAmount"));
        [Column]
        public decimal TotalAmount
        {
            get { return GetProperty(TotalAmountProperty); }
            set { SetProperty(TotalAmountProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<string> PlaceProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<string>("Place"));
        [Column]
        public string Place
        {
            get { return GetProperty(PlaceProperty); }
            set { SetProperty(PlaceProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<DateTime> EndDateProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<DateTime>("EndDate"));
        [Column]
        public DateTime EndDate
        {
            get { return GetProperty(EndDateProperty); }
            set { SetProperty(EndDateProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<string> TypeProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<string>("Type"));
        [Column]
        public string Type
        {
            get { return GetProperty(TypeProperty); }
            set { SetProperty(TypeProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<string> WorkFlowInsIdProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<string>("WorkFlowInsId"));
        [Column]
        public string WorkFlowInsId
        {
            get { return GetProperty(WorkFlowInsIdProperty); }
            set { SetProperty(WorkFlowInsIdProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<string> WorkTaskInsIdProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<string>("WorkTaskInsId"));
        [Column]
        public string WorkTaskInsId
        {
            get { return GetProperty(WorkTaskInsIdProperty); }
            set { SetProperty(WorkTaskInsIdProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<Guid> FinancialUserIDProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<Guid>("FinancialUserID"));
        [Column]
        public Guid FinancialUserID
        {
            get { return GetProperty(FinancialUserIDProperty); }
            set { SetProperty(FinancialUserIDProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<DateTime> FinancialDateProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<DateTime>("FinancialDate"));
        [Column]
        public DateTime FinancialDate
        {
            get { return GetProperty(FinancialDateProperty); }
            set { SetProperty(FinancialDateProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<decimal> FinancialActualAmountProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<decimal>("FinancialActualAmount"));
        [Column]
        public decimal FinancialActualAmount
        {
            get { return GetProperty(FinancialActualAmountProperty); }
            set { SetProperty(FinancialActualAmountProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<Guid> ConferenceUserIDProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<Guid>("ConferenceUserID"));
        [Column]
        public Guid ConferenceUserID
        {
            get { return GetProperty(ConferenceUserIDProperty); }
            set { SetProperty(ConferenceUserIDProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<DateTime> ConferenceDateProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<DateTime>("ConferenceDate"));
        [Column]
        public DateTime ConferenceDate
        {
            get { return GetProperty(ConferenceDateProperty); }
            set { SetProperty(ConferenceDateProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        private static PropertyInfo<decimal> ConferenceActualAmountProperty = RegisterProperty(typeof(V_bpm_OpenClassBudgetMaster), new PropertyInfo<decimal>("ConferenceActualAmount"));
        [Column]
        public decimal ConferenceActualAmount
        {
            get { return GetProperty(ConferenceActualAmountProperty); }
            set { SetProperty(ConferenceActualAmountProperty, value); }
        }
        #endregion

        #region Validation Rules 验证规则
        //将验证规则与业务对象的属性联系在一起
        protected override void AddBusinessRules()
        {
            //AddRule的第一个参数是委托变量，也就是说是方法的变量
            ValidationRules.AddRule(CommonRules.StringRequired, "txtProductLayoutID");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("txtProductLayoutID", 80));
            ValidationRules.AddRule(CommonRules.StringRequired, "ProductLayoutID");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("ProductLayoutID", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "Contact");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Contact", 80));
            ValidationRules.AddRule(CommonRules.StringRequired, "Subject");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Subject", 100));
            ValidationRules.AddRule(CommonRules.StringRequired, "Project");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Project", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "DetailsProject");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("DetailsProject", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "Remark");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Remark", 80));
            ValidationRules.AddRule(CommonRules.StringRequired, "DetailsExpenses");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("DetailsExpenses", 40));
            ValidationRules.AddRule(CommonRules.StringRequired, "Precautions");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Precautions", 100));
            ValidationRules.AddRule(CommonRules.StringRequired, "bpmTitle");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("bpmTitle", 100));
            ValidationRules.AddRule(CommonRules.StringRequired, "Place");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Place", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "Type");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Type", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "WorkFlowInsId");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("WorkFlowInsId", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "WorkTaskInsId");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("WorkTaskInsId", 50));
            //base.AddBusinessRules();
        }
        #endregion

        #region Factory Methods 工厂方法

        public V_bpm_OpenClassBudgetMaster() { }

        public static V_bpm_OpenClassBudgetMaster New()
        {
            return DataPortal.Create<V_bpm_OpenClassBudgetMaster>();
        }
        public static V_bpm_OpenClassBudgetMaster Get(Guid OcbdID)
        {
            return DataPortal.Fetch<V_bpm_OpenClassBudgetMaster>(new SingleLazyCriteria<V_bpm_OpenClassBudgetMaster, Guid>(OcbdID, false));
        }
        public static void Delete(Guid OcbdID)
        {
            DataPortal.Delete(OcbdID);
        }

        #endregion

        #region Data Access 数据访问
        //由于DataPortal_create中没有对数据库的访问，所有标记了Runlocal特性，使得该方法只需在本地运行即可
        //如果代码中有访问数据库的方法，那么就不要用这个特性，使数据门户可以根据情况将此方法的运行选择在应用服务器还是本地
        [RunLocal()]
        protected override void DataPortal_Create()
        {
            //在此调用CheckRules对所有的属性进行验证规则的检查，这样检查只运行一次。
            ValidationRules.CheckRules();
        }


        //可以看到此方法没有标记任何特性
        //此方法要访问数据库所以不能标记本地，由于她没有任何数据库更新操作所以也无需事务性的保护
        //此方法调用结束后会隐含的调用MarkOld（）方法
        private void DataPortal_Fetch(Guid OcbdID)
        {
            //通过连接字符串建立SQL连接对象，Using符号代表，范围释放的意思，SqlConnection对象会在此范围后被释放掉
            using (var ctx = ConnectionManager<SqlConnection>.GetManager(ConnectionStringNames))
            {
                IDb db = DbFactory.Instance.GetDb(ctx.Connection);
                IQuery q = db.Query();
                q.Constrain("OcbdID").Equal(OcbdID);

                var data = db.Select<V_bpm_OpenClassBudgetMaster>(q)[0];
                LoadProperty(OcbdIDProperty, data.OcbdID);
                LoadProperty(IDProperty, data.ID);
                LoadProperty(BeginDateProperty, data.BeginDate);
                LoadProperty(txtProductLayoutIDProperty, data.txtProductLayoutID);
                LoadProperty(ProductLayoutIDProperty, data.ProductLayoutID);
                LoadProperty(RecIDProperty, data.RecID);
                LoadProperty(ContactProperty, data.Contact);
                LoadProperty(SubjectProperty, data.Subject);
                LoadProperty(ProjectProperty, data.Project);
                LoadProperty(DetailsProjectProperty, data.DetailsProject);
                LoadProperty(BudgetAmountProperty, data.BudgetAmount);
                LoadProperty(ActualAmountProperty, data.ActualAmount);
                LoadProperty(RemarkProperty, data.Remark);
                LoadProperty(DetailsExpensesProperty, data.DetailsExpenses);
                LoadProperty(PrecautionsProperty, data.Precautions);
                LoadProperty(bpmTitleProperty, data.bpmTitle);
                LoadProperty(TotalAmountProperty, data.TotalAmount);
                LoadProperty(PlaceProperty, data.Place);
                LoadProperty(EndDateProperty, data.EndDate);
                LoadProperty(TypeProperty, data.Type);
                LoadProperty(WorkFlowInsIdProperty, data.WorkFlowInsId);
                LoadProperty(WorkTaskInsIdProperty, data.WorkTaskInsId);
                LoadProperty(FinancialUserIDProperty, data.FinancialUserID);
                LoadProperty(FinancialDateProperty, data.FinancialDate);
                LoadProperty(FinancialActualAmountProperty, data.FinancialActualAmount);
                LoadProperty(ConferenceUserIDProperty, data.ConferenceUserID);
                LoadProperty(ConferenceDateProperty, data.ConferenceDate);
                LoadProperty(ConferenceActualAmountProperty, data.ConferenceActualAmount);
            }
        }

        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_DeleteSelf()
        {
            //依然是调用下面的方法删除的，只是他此时可以获得自己的Id
            DataPortal_Delete(OcbdIDProperty);
        }
        #endregion
    }
}

